package com.demo.ObjectOutputStream_;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @author gy
 * @date 2022/4/5
 */
public class ObjectOutputStream01 {
    public static void main(String[] args) {
        String filePath = "f:\\20220403\\ObjectOutputStream01.xyz";
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream(filePath));

            oos.writeInt(100);
            oos.writeBoolean(true);
            oos.writeChar('a');
            oos.writeDouble(1.00);
            oos.writeUTF("hello,ObjectOutputStream01");

            oos.writeObject(new Dog("大黄","10","黄色",new Master("Bob")));

            System.out.println("序列化完成========成功的将 数据类型 和 数据 值 导入自定义的文件中");

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (oos != null) {
                    oos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

